<?php
require_once ("src/db/connectdatabase.php");

function getAdvertise($id) {
	$con = new ConnectDB();
	$tbl = "thongbaodealer";
	$fn = array('titletb', 'message', 'datecreate');
	$condetion = array('id' => $id);
	return $con -> getvalue($tbl, $fn, $condetion);
}

function getAdvertiresOrder($id) {
	$con = new ConnectDB();
	$sql = "SELECT id, titletb, sendalldealer, datecreate FROM thongbaodealer WHERE id<>'".$id."' AND isuse='1' ORDER BY datecreate DESC";
	return $con -> getvalueString($sql);
}

if(isset($_GET['id'])) {
$arrdatas = getAdvertiresOrder($_GET['id']);

?>
<div class="intrl_txt" style="margin: auto;">
    <div style="float: left; clear: right;">
        <div style="width: 100%; /* [disabled]height: auto; */ margin-top: 0px; float: left; clear: right;">
            <div style="height: auto; float:left; clear:right;">
            <?php
        
            $arrnew = getAdvertise($_GET['id']);
            if(count($arrnew) > 0) {
            ?>
                <h1 class="text3" style="width: 100%; margin-top:0px; clear:right; font-size:23px; text-transform:none; color:#88a943;"><strong><?php echo($arrnew[0][0]) ?></strong></h1><span style="font-size:12px;"><i>Cập nhật ngày: <?php echo(int_to_date($arrnew[0][2])) ?></i></span>
                <div style="clear:both; height:15px;"></div>
                <div id="txt" style="width: 100%;"><?php echo($arrnew[0][1]) ?></div>
                <div style="clear:both;"></div>
                <?php
            }
                ?>
            </div>
        </div>
	</div>
    <div style="clear: both; height: 30px"></div>
    <div id="txt">
    	<div><h1 class="text3" style="width: 100%; margin-top:0px; clear:right; font-size:20px; text-transform:none; color:#88a943;">Thông báo mới nhất:</h1></div>
		<?php 
        if(count($arrdatas) > 0) {
        ?>
        <table width="960px" border="0" cellpadding="1" cellspacing="1" bgcolor="#d5cfb1">
            <tbody>
                <?php
                foreach($arrdatas as $entry) {
                    $strbanknameurl = $entry[1];
                    $strbanknameurl = rewriteTextUrl(stripUnicode($strbanknameurl));
                ?>
                <tr bgcolor="#EFEEEE">
                    <td height="25" align="left" bgcolor="#FFFFFF" class="tbl_txt"><strong><a href="<?php echo($host) ?>profile/chi-tiet-thong-bao/<?php echo($entry[0]) ?>/<?php echo($strbanknameurl) ?>.html"><?php echo($entry[1]) ?></a></strong> <?php echo(int_to_date($entry[3])) ?></td>
                </tr>
                <tr></tr>
                <?php
                }
                ?>
            </tbody>
        </table>
        <?php
        }
        ?>
    </div>
</div>
<?php
}
?>